package com.ivc.info.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cs.framework.common.bo.Message;
import com.cs.framework.ui.bo.UIData;
import com.cs.framework.ui.web.UI;
import com.cs.framework.web.annotation.Action;
import com.cs.framework.web.annotation.Mapping;
import com.cs.framework.web.handler.Web;
import com.ivc.info.dto.base.SupplierDto;
import com.ivc.info.service.SupplierService;

/**
 * 供应商
 * 
 * @author hedongzhou
 * 
 */
@Action("supplier")
public class SupplierAction {

	private Log logger = LogFactory.getLog(getClass());

	@Resource
	private SupplierService supplierService;

	/**
	 * 进入供应商管理页面
	 */
	@Mapping
	public void mainPage() {
		UI.returnPage("info_spl");
	}

	/**
	 * 查询供应商
	 */
	@Mapping
	public Object query() {
		SupplierDto supplierDto = Web.bind(SupplierDto.class);

		List<SupplierDto> list = supplierService.query(supplierDto);
		int count = supplierService.count(supplierDto);

		return new UIData(list, count);
	}

	/**
	 * 新增供应商
	 */
	@Mapping
	public Object save() {
		SupplierDto supplierDto = Web.bind(SupplierDto.class);

		try {
			supplierService.save(supplierDto);

			return new Message("Y", "新增成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

	/**
	 * 修改供应商
	 */
	@Mapping
	public Object update() {
		SupplierDto supplierDto = Web.bind(SupplierDto.class);

		try {
			supplierService.update(supplierDto);

			return new Message("Y", "修改成功");
		} catch (Exception e) {
			logger.error(e.getMessage(), e);

			return new Message("N", e.getMessage());
		}
	}

}
